﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Net;
using System.IO;

namespace StWapBrowser.BLL
{
    class HtmlOp
    {
        public HtmlOp()
        { }

        public string GetHtml(string url,Encoding encode)
        {
            string result = "";

            HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

            using (Stream stream = httpWebResponse.GetResponseStream())
            {
                long fileSizeInBytes = httpWebResponse.ContentLength;

                //创建文件流对象
                int length = 10240;
                byte[] buffer = new byte[10250];
                int byteSread = 0;
               
                while ((byteSread = stream.Read(buffer, 0, length)) > 0)
                {    
                    //把数据写入文件
                    result += encode.GetString(buffer, 0, byteSread);
                }
            }
            return result;
        }
    }
}
